package dibazhou;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Map<String,Integer> map=new HashMap<String,Integer>();
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext())
		{
			String key=sc.next();
			if(key.equals("!!!!!"))	break;
			Integer cnt=map.get(key);
			if(cnt==null){
				map.put(key, 1);
			}
			else{
				map.put(key, cnt+1);
			}
		}
		System.out.println(map.size());
		List<Map.Entry<String,Integer>> entryList=new ArrayList<Map.Entry<String,Integer>>(map.entrySet());
		Collections.sort(entryList, new Comparator<Map.Entry<String,Integer>>() {

			@Override
			public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
				if (o1.getValue() == o2.getValue())
					return o1.getKey().compareTo(o2.getKey());
				return o2.getValue() - o1.getValue() ;
			}
		});
		for (int i = 0; i < 10; i++) {
			System.out.println(entryList.get(i));
		}
		sc.close();

	}

}
